<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    

<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<link rel="stylesheet" type="text/css" href="css/maintable.css"></link>

</head>
	<script >
	//页面加载完，查询一级分类
		$(function(){
			$.ajax({
				type:"POST",
				url:"CateServlet.do",
				data:{flog:"search",parentId:"0"},
				async:false,
				dataType:"json",
				success:function(cates){
					
					$("select[name=bigCateId]").empty();
					$("select[name=bigCateId]").append("<option value=''>==请选择一级分类==</option>");
					$.map(cates,function(v,k){
						$("select[name=bigCateId]").append("<option value='"+v.id+"'>"+v.cateName+"</option>");
						if(v.id==${goodsInfo.bigCateId}+""){
							$("select[name=bigCateId]").val(${goodsInfo.bigCateId});
						}
					});

				}
			});
		});
	</script>
	<script >
	//一级分类改变，查询二级分类
		$(function(){
			$("select[name=bigCateId]").change(function(){
				if($("select[name=bigCateId]").val()==""){
					$("select[name=smallCateId]").empty();
					$("select[name=smallCateId]").append("<option value=''>==请选择一级分类==</option>");
				}else{
					$.ajax({
						type:"POST",
						url:"CateServlet.do",
						data:{flog:"search",parentId:this.value},
						async:false,
						dataType:"json",
						success:function(cates){
							
							$("select[name=smallCateId]").empty();
							$("select[name=smallCateId]").append("<option value=''>==请选择二级分类==</option>");
							$.map(cates,function(v,k){
								$("select[name=smallCateId]").append("<option value='"+v.id+"'>"+v.cateName+"</option>");
							});
						}
					});
				}
			});
		});
	</script>
	<script >
		$(function(){
			if(""!=${goodsInfo.bigCateId}+""){
				$.ajax({
					type:"POST",
					url:"CateServlet.do",
					data:{flog:"search",parentId:${goodsInfo.bigCateId}+""},
					async:false,
					dataType:"json",
					success:function(cates){
						
						$("select[name=smallCateId]").empty();
						$("select[name=smallCateId]").append("<option value=''>==请选择二级分类==</option>");
						$.map(cates,function(v,k){
							$("select[name=smallCateId]").append("<option value='"+v.id+"'>"+v.cateName+"</option>");
							if(v.id==${goodsInfo.smallCateId}+""){
								$("select[name=smallCateId]").val(${goodsInfo.smallCateId});
							}
						});
					}
				});
			}
		});
	</script>
	<script>
	    function setImagePreview(docObj, localImagId, imgObjPreview, width, height) {
			if (docObj.files && docObj.files[0]) { //火狐下，直接设img属性        
				imgObjPreview.style.display = 'block';
				imgObjPreview.style.width = width;
				imgObjPreview.style.height = height;
				//火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式        
				imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
			} else { //IE下，使用滤镜      
				docObj.select();
				var imgSrc = document.selection.createRange().text;
				//必须设置初始大小        
				localImagId.style.width = width;
				localImagId.style.height = height;
				//图片异常的捕捉，防止用户修改后缀来伪造图片        
				try {
					localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
					localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
				} catch (e) {
					alert("您上传的图片格式不正确，请重新选择!");
					return false;
				}
				imgObjPreview.style.display = 'none';
				document.selection.empty();
			}
		}
	  </script>

<body>
	<div class="div_title">
		<div class="div_titlename">
			<img src="images/san_jiao.gif"><span>修改商品信息</span>
		</div>
	</div>
	
	 <form action="GoodsServlet.do?flog=changeGoods" method="post" enctype="multipart/form-data" >
	 	<input name="id" value="${goodsInfo.id}" type="hidden">
	 	<table class="main_table">
	 		
	 		<tr>
	 			<td>商品名称:</td>
	 			<td><input name="goodsName" value="${goodsInfo.goodsName}" ></td>
	 		</tr>
	 		<tr>
	 			<td>所属大分类:</td>
	 			<td>
	 				<select name="bigCateId" >
						<option value="">==请选择一级分类==</option>
				 	</select> 
	 			</td>
	 		</tr>
	 		<tr>
	 			<td>所属小分类:</td>
	 			<td>
	 				<select name="smallCateId" >
						<option value="">==请选择二级分类==</option>
				 	</select> 
				  
				</td>
	 		</tr>
	 		<tr>
	 			<td>计量单位:</td>
	 			<td><input name="unit" value="${goodsInfo.unit}" ></td>
	 		</tr>
	 		<tr>
	 			<td>商品价格:</td>
	 			<td><input name="price" value="${goodsInfo.price}" ></td>
	 		</tr>
	 		<tr>
	 			<td>生产厂商:</td>
	 			<td><input name="producter" value="${goodsInfo.producter}" > </td>
	 		</tr>
	 		<tr>
	 			<td>商品图片 :</td>
	 			<td>
	 				<input name="picture" type="file" onchange="setImagePreview(this,localImag,preview,'100px','125px');"> 
				   <div id="localImag" style="margin-left: 24px" ></div>
				   <img id="preview" alt="请上传图片"  src="GoodsServlet.do?flog=showPicture&goodsId=${goodsInfo.id }"  />
	 			</td>
	 		</tr>
	 		<tr>
	 			<td>备注信息:</td>
	 			<td><textarea name="des">${goodsInfo.des}</textarea> </td>
	 		</tr>
	 		<tr>
	 			<td><input type="submit" value="提交"></td>
	 			<td></td>
	 		</tr>
	 	</table>
	</form>
	 ${msg }			
				 
</body>
</html>	
